package com.example.lanouhn.firstapp.activity.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import com.example.lanouhn.firstapp.R;
import com.example.lanouhn.firstapp.activity.activity.MainActivity;
import com.example.lanouhn.firstapp.activity.activity.NotifyActivity;
import com.example.lanouhn.firstapp.activity.activity.StartActivity;

/**
 * 定义dialog弹出对话框的工具类
 * Created by lanouhn on 16/7/28.
 */
public class DialogUtil
{
    //定义一个显示消息的对话框
    public static void showDialog(final Context context,String msg, boolean goHome)
    {
        //创建一个Dialog.B
        AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(msg).setCancelable(false);
        if (goHome)
        {
         builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
         {
             @Override
             public void onClick(DialogInterface dialogInterface, int i)
             {
                 //检测输入密码是否正确   正确时候进行跳转
                 Intent intent = new Intent(context, StartActivity.class);
                 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                 context.startActivity(intent);
             }
         });
        }else{
            builder.setPositiveButton("确定",null);
        }
        builder.create().show();
    }
    //定义一个显示指定组建的对话框
    public static void showDialog(Context context,View view){
        new AlertDialog.Builder(context).setView(view).setCancelable(false)
                .setPositiveButton("确定",null).create().show();
    }

    /**
     *
     */
    public static void showDialog2(final Context context,String msg, boolean goHome) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(msg).setCancelable(false);

        //设置图标
        builder.setIcon(R.mipmap.ic_launcher);
        //设置标题
        builder.setTitle("提示");
            builder.setPositiveButton("去购物车", new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialogInterface, int i)
                {
                    //检测输入密码是否正确   正确时候进行跳转
                    Intent intent = new Intent(context, MainActivity.class);
                    intent.putExtra("symbol",3);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    context.startActivity(intent);
                }
            });
            builder.setNeutralButton("继续逛逛", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
//            builder.setPositiveButton("继续逛逛",null);

        //创建并显示
        builder.create().show();
    }
    public static void showDialog3(final Context context,String msg, boolean goHome) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(msg).setCancelable(false);

        //设置图标
        builder.setIcon(R.mipmap.ic_launcher);
        //设置标题
        builder.setTitle("提示");
        builder.setPositiveButton("网络连接失败，请点击重试", new DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialogInterface, int i)
            {
                //检测输入密码是否正确   正确时候进行跳转
                Intent intent = new Intent(context, MainActivity.class);
                intent.putExtra("symbol",3);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                context.startActivity(intent);
            }
        });


        //创建并显示
        builder.create().show();
    }
    public static void showDialog4(final Context context,String msg, boolean goHome) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(msg).setCancelable(false);

        //设置图标
        builder.setIcon(R.mipmap.ic_launcher);
        //设置标题
        builder.setTitle("提示");
        builder.setPositiveButton("网络连接失败，请点击重试", new DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialogInterface, int i)
            {
                //发送广播到通知页面进行接收，重新加载 线程
                Intent it = new Intent();
                it.setAction("notify");
                context.sendBroadcast(it);
            }
        });


        //创建并显示
        builder.create().show();
    }
}
